<?php

/**
 * 随机生成两个时间间隔中的时间
 * @param $beginTime
 * @param $endTime
 * @return false|string
 */
function randomDate($beginTime, $endTime) {

    $begin = strtotime($beginTime);
    $end = strtotime($endTime);
    $timestamp = rand($begin, $end);

    return date("Y-m-d H:i:s", $timestamp);

}

function formatLastMessageTime($lastTime) {

    $now = date("Y/m/d");
    $lastDate = date("Y/m/d", strtotime($lastTime));

    $formatTime = date("Y/m/d H:i", strtotime($lastTime));

    if($now == $lastDate) {

        $lastHour = date("H", strtotime($lastTime));

        if($lastHour >= 0 && $lastHour <= 11) {
            $formatTime = "上午". date("H:i", strtotime($lastTime));
        } else {
            $formatTime = "下午". date("H:i", strtotime($lastTime));
        }

    }

    return $formatTime;

}